Reading Assignment 2

OpenMP

Write your answers in a PDF and upload the document on Gradescope for submission. The due date is given on Gradescope. Each question is worth 10 points.

Starter code for all the questions.

Please watch the videos 06 through 12 and the slides before answering the questions:

Answer these questions:

  1. In cpp_thread.cpp, complete the exercise with function f4. Your code should pass the assert. Turn in your code.
  2. In cpp_thread.cpp, complete the exercise with t6 and max_result. Your code should pass the assert. Turn in your code.
  3. In mutex_demo.cpp, explain what would happen if you remove line 45: g_mutex.unlock();
  4. In hello_world_openmp.cpp, explain what the line 60 does: #pragma omp parallel num_threads(nthreads). Explain the num_threads clause.
  5. Using an OpenMP pragma, modify the file matrix_prod_openmp.cpp such that the execution of the code between line 90 and 99 is accelerated by using multiple threads. Report on your running times as you vary the number of threads. Use the options -p and -n. Turn in your code.
  6. In shared_private_openmp.cpp, explain what would happen if you remove private(is_private) on line 31.